using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using AntDesign;
using AntDesign.Charts;
using AntDesign.ProLayout;
using System.Net.Http;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Http;
using Microsoft.JSInterop;
using ZFY.UMC.BlazorWebAssembly;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using ZFY.UMC.BlazorWebAssembly.Shared;
using Microsoft.AspNetCore.Components.Authorization;
using ZFY.Core;
using Microsoft.Extensions.Configuration;

namespace ZFY.UMC.BlazorWebAssembly
{
    public partial class BasicLayout
    {
        private readonly MenuDataItem[] _menuData = {new MenuDataItem{Path = "/", Name = "welcome", Key = "welcome", Icon = "smile", }, new MenuDataItem{Path = "/usermanage", Name = "usermanage", Key = "usermanage", Icon = "smile", }};
        [CascadingParameter]
        private Task<AuthenticationState> AuthenticationStateTask { get; set; }
        [Inject]
        public CurrentUserProfile CurrentUserProfile { get; set; }
        
        //[Inject]
        //public IConfiguration Configuration { get; set; }
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            

            await base.SetParametersAsync(parameters);
        }

        protected override async Task OnInitializedAsync()
        {
            var res = await AuthenticationStateTask;
           
            CurrentUserProfile.PhoneNumber = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.PhoneNumber)?.Value;
            CurrentUserProfile.UserName = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.Name)?.Value;
            CurrentUserProfile.Avatar = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.Avatar)?.Value;

            CurrentUserProfile.Email = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.Email)?.Value;
            CurrentUserProfile.NickName = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.NickName)?.Value;
            CurrentUserProfile.UserId = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.UserId)?.Value;
            CurrentUserProfile.Address = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.Address)?.Value;
            CurrentUserProfile.Birthday = res.User.Claims.FirstOrDefault(x => x.Type == ZFYProfileClaimTypes.Birthday)?.Value;

            foreach (var item in res.User.Claims)
            {
                Console.WriteLine(item.Type);
                Console.WriteLine(item.Value);
            }
            Console.WriteLine(CurrentUserProfile.Email);
            Console.WriteLine(CurrentUserProfile.Avatar);

            await base.OnInitializedAsync();
        }
    }
}